
#include <inttypes.h>
#include <wiring.h>


class InputFeedbackLoop
{
  private:  
  //Private variables
    const static uint16_t bufferSize = 5;
    uint16_t bufferedInput[bufferSize];
    uint16_t countOfBuffer;
    uint16_t sumOfBuffer;
    int currentBufferAverage;
    int previousBufferAverage;
  
    float inputDampener;
    float feedbackMagnifier;
    float calibrationAdjustMaximum;
  
    uint16_t calibrationCount;
    int calibration;
    uint16_t calibrationAdjust;
  

    float degreeTransitionConstant;
    uint16_t lastInput;
    uint8_t inputPin;
  
    int currentInputAwayFromCalibration;
    int currentDegreeOutputFrom90;
    float firstIntegrationSinceStart;  
    float secondIntegrationSinceStart; 
    unsigned long previousTime;
    unsigned long currentTime;
    long deltaTime;
    // End Prizvate Variables
  
  //private functions
    uint16_t getPinInput();
    void calculateActualDegreeChanges();
    void adjustCalibration();
    void readNewInput();
    void adjustChangeSinceStart();
    unsigned long milisecondsSinceOn();
  //end private functions
  public:  
    InputFeedbackLoop(uint8_t newInputPin, float newInputDampener, float newFeedbackMagnifier, float newCalibrationAdjustMaximum, float newDegreeTransitionConstant);
    void reset();
    void Calibrate();
    int ReadAndAverageOverBuffer();
    int getDegrees();    
    float getFirstIntegrationSinceStart();
    float getSecondIntegrationSinceStart();
    int LastInput();
    int Calibration();
    int CurrentBufferAverage();
    void InitializeBuffer();
    int CurrentInputAwayFromCalibration();
};
